package com.hairline.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hairline.bean.Topic;
import com.hairline.bean.TopicExample;
import com.hairline.bean.vo.ListVo;
import com.hairline.bean.vo.WxListVo;
import com.hairline.bean.vo.WxTopicVo;
import com.hairline.mapper.TopicMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service
public class WxTopicServicesImpl implements WxTopicServices {
    @Autowired
    TopicMapper topicMapper;

    @Override
    public WxListVo getTopicList(Integer page, Integer size) {
        PageHelper.startPage(page,size);
        TopicExample topicExample = new TopicExample();
        List<Topic> topics = topicMapper.selectByExample(topicExample);
        PageInfo<Topic> topicPageInfo = new PageInfo<>(topics);
        long total = topicPageInfo.getTotal();


        WxListVo wxListVo = new WxListVo();
        wxListVo.setData(topics);
        wxListVo.setCount(total);
        return wxListVo;
    }

    @Override
    public  WxTopicVo getTopicDetailById(Integer id) {
        WxTopicVo wxTopicVo = topicMapper.selectByPrimaryKeyCustomized(id);
        return wxTopicVo;
    }

    @Override
    public List<Topic> getTopicRelated(Integer id) {
        TopicExample topicExample = new TopicExample();

        List<Topic> topics = topicMapper.selectByExample(topicExample);
        List<Topic> topicsReturn = topics.subList(0, 4);



        return topicsReturn;
    }


}
